// 第一题
// 实现一个sleep函数，比如slepp(1000)意味着等待1000毫秒，
// 可以从promise、Generator、Async/Await等角度实现

const Sleep =  {
    sleepInPromise: function(times) {
        return new Promise(resolve => {
            setTimeout(resolve, times);
        })
    },
    sleepInGenerator: function*(times) {
        yield new Promise(resolve => {
            setTimeout(resolve, times);
        })
    }
};

let fn = function() {
    console.log('hello word!!!!');
};

// Sleep.sleepInPromise(1000).then(fn);

async function testFn () {
    await Sleep.sleepInPromise(1000);
    fn();
}

// testFn();


Sleep.sleepInGenerator(1000).next().value.then(fn);
console.log(Sleep.sleepInGenerator(1000))